package com.hongxun.modules.csg.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.csg.dao.CStackPointDao;
import com.hongxun.modules.csg.entity.CStackPointEntity;
import com.hongxun.modules.csg.service.CStackPointService;



@Service("cStackPointService")
public class CStackPointServiceImpl implements CStackPointService {
	@Autowired
	private CStackPointDao cStackPointDao;
	
	@Override
	public CStackPointEntity queryObject(String guid){
		return cStackPointDao.queryObject(guid);
	}
	
	@Override
	public List<CStackPointEntity> queryList(Map<String, Object> map){
		return cStackPointDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return cStackPointDao.queryTotal(map);
	}
	
	@Override
	public void save(CStackPointEntity cStackPoint){
        if(cStackPoint.getGuid()==null||cStackPoint.getGuid().equals("")) {

		    cStackPoint.setGuid(UUID.randomUUID().toString());
        }
		cStackPointDao.save(cStackPoint);
	}
	
	@Override
	public void update(CStackPointEntity cStackPoint){
		cStackPointDao.update(cStackPoint);
	}
	
	@Override
	public void delete(String guid){
		cStackPointDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		cStackPointDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<CStackPointEntity> entities) {
		for (CStackPointEntity d : entities) {
			if (d.getSPDatastate().equals("删除")) {
				cStackPointDao.delete(d.getGuid());
			} else {
				CStackPointEntity cStackPointEntity = cStackPointDao.queryObject(d.getGuid());
				if (cStackPointEntity == null) {
					cStackPointDao.save(d);
				} else {
					cStackPointDao.update(d);
				}
			}
		}
	}

}
